
use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop local_shock* j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

gen log_diesel_rotterdam_euro=ln(diesel_rotterdam_euro)
gen log_prix_ht=ln(prix_ht)

capture drop local_shock*
capture drop last_digit
capture drop change_price
capture drop psychological_prices
capture drop sum_psy sum_change
capture drop idb
capture drop log_petoile
gen log_petoile=.

sum id
gen id2_str = string(id,"%05.0f")
egen id2=group(id2_str)
drop id2_str

sum id2

xtset id2 daten


forvalues i=200 (200) 3200 {
local j=`i'-200

preserve

keep if id2>`j' & id2<=`i'
keep id id2 log_prix_ht log_diesel_rotterdam_euro daten log_petoile prix 
forvalues z=`j'(1)`i'{
qui reg log_prix_ht log_diesel_rotterdam_euro if prix!=l.prix // Régressions le jour du changement
qui predict log_petoile_temp if id2==`z'
qui replace log_petoile=log_petoile_temp if id2==`z'
drop log_petoile_temp 
di `z'
}
keep id id2 log_prix_ht log_diesel_rotterdam_euro daten log_petoile  prix 
save "$path\Intermediary Data\p_minus_pstar\petoile_`j'_`i'_psychologicalprices_logregression.dta", replace
restore
}
